#-*- coding:utf-8 -*-
'''
@date:2013年9月29日
@author: JeffXun
'''


class _CQueue:
    """ """
    def __init__(self,pop=1):
        """ """
        self._index = 0;
        if pop <=0:
            raise Exception,"pop must Positive number"
        self._pop = pop;
        self._queue = [];
        
    def __iter__(self):
        """ """
        return self;
    
    def get(self):
        """ """
        if self._index >= len(self._queue):
            self._index = 0;
        end = self._index + self._pop;
        if end >= len(self._queue):
            end = len(self._queue)
        result = self._queue[self._index:end];
        self._index = self._index + self._pop;
        return result
    
    def next(self):
        if self._index < len(self._queue):
            end = self._index + self._pop;
            if end >= len(self._queue):
                end = len(self._queue)
            result = self._queue[self._index:end];
            self._index = self._index + self._pop;
            return result
        else:
            raise StopIteration;
    
    def add(self,obj):
        """ """
        self._queue.append(obj);
        
    def remove(self,obj):
        """ """
        self._queue.remove(obj);
    
    def clear(self):
        """ """
        self._queue = []
        
#pop 分段数
def newQueue(pop = 1):
    if pop <= 0:
        raise Exception,"pop must be a Positive number"
    return _CQueue(pop)
